package com.heaven.customerServer.customerController;

import com.heaven.customerServer.customerController.vo.login.LoginRes;
import com.heaven.customerServer.customerController.vo.user.UserInfoRes;
import com.heaven.service.SearchService;
import com.heaven.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("heaven-server/search")
public class SearchController {
    @Resource
    private SearchService searchService;
    @Resource
    private LoginController loginController;

    /**
     * 搜索用户
     * @param keyword 关键字
     * @param sort 排序方式：{字段}-{ASC|DESC}
     */
    @RequestMapping("/user")
    public R searchUser(@RequestParam("keyword") String keyword,
                        @RequestParam("sort")String sort){
        LoginRes.UserSession userSession = loginController.getUserSession();
        List<UserInfoRes> ans = searchService.searchUser(keyword, sort, userSession == null ? "" : userSession.getUserId());
        return R.okData(ans);
    }
}
